using System.Runtime.Serialization;
using System;
using System.Diagnostics;

namespace CCWP7.Model
{
    [DataContract]
    [KnownType(typeof(ServerReport))]
    public class Server
    {
        public Server()
        {
            Id = GenerateId();
        }

        public Server(string name, string fullServerUri)
        {
            Debug.Assert(!String.IsNullOrEmpty(name), "name is null or empty.");
            Debug.Assert(!String.IsNullOrEmpty(fullServerUri), "fullServerUri is null or empty.");

            Name = name;
            Uri = fullServerUri;
            Id = GenerateId();
        }

        [DataMember]
        public string Name { get; set; }
        [DataMember]
        public string Uri { get; set; }
        [DataMember]
        public DateTime? LastReportRead { get; set; }
        [DataMember]
        public IServerReport Report { get; set; }
        [DataMember]
        public string Id { get; set; }

        static string GenerateId()
        {
            return Guid.NewGuid().ToString("N");
        }

        public string SafeGetId()
        {
            if (string.IsNullOrEmpty(Id))
                return Id = GenerateId();
            else
                return Id;
        }
    }
}
